package com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.ydkj.a37e_mall.Classes.Applicatiom.MyApplication;
import com.ydkj.a37e_mall.Classes.Model.Request.MessageStatusReq;
import com.ydkj.a37e_mall.R;
import com.ydkj.a37e_mall.Resource.Utils.CommonUtil;
import com.ydkj.a37e_mall.Resource.Utils.Const;
import com.ydkj.a37e_mall.Resource.Utils.Rsa;
import com.ydkj.a37e_mall.Resource.Utils.SharedPreferencesUtil;
import com.ydkj.a37e_mall.Resource.View.StatusBarUtil;

import org.json.JSONObject;

import cz.msebera.android.httpclient.Header;

/**
 * Created by Administrator on 2017/2/27.
 * <p>
 * 消息详细
 */

public class MessageDetails extends BaseActivity {

    private Activity mActivity;
    private SharedPreferencesUtil sharedPreferencesUtil;
    private MyApplication myApplication;
    private ImageView img_back;
    private TextView tv_time, tv_title, tv_describe;
    private int id;
    private String flag, time, title, desc;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.message_details);

        mActivity = this;
        init();
        initWindow();//沉浸式状态栏
    }

    private void initWindow() {
        StatusBarUtil.setColor(mActivity, getResources().getColor(R.color.A000000), 0);
    }

    private void init() {
        myApplication = MyApplication.getInstance();
        sharedPreferencesUtil = SharedPreferencesUtil.getInstance(this);
        if (this.getIntent().getExtras() != null) {
            flag = this.getIntent().getStringExtra("flag");
            id = this.getIntent().getIntExtra("id", 0);
            time = this.getIntent().getStringExtra("time");
            title = this.getIntent().getStringExtra("title");
            desc = this.getIntent().getStringExtra("desc");
        }

        img_back = (ImageView) mActivity.findViewById(R.id.img_back);
        tv_time = (TextView) mActivity.findViewById(R.id.tv_time);
        tv_title = (TextView) mActivity.findViewById(R.id.tv_title);
        tv_describe = (TextView) mActivity.findViewById(R.id.tv_describe);

        if (flag.equals("messages")) {
            SetVipMessageStatus(id);
        }

        tv_time.setText(time);
        tv_title.setText(title);
        tv_describe.setText(desc);
        img_back.setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            finish();
                                        }
                                    }
        );
    }

    //    //设置是否已读
    private void SetVipMessageStatus(int id) {
        MessageStatusReq req = new MessageStatusReq();

        req.setUuid(myApplication.getDataEntity().getUuid());


        RequestParams params = new RequestParams();
        params.put("id", id);
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());
        Log.e("url", "params==" + params);

        AsyncHttpClient client = new AsyncHttpClient();
        client.put(Const.COMMON_ADDRESS + req.urlString() + id, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                Log.e("url", "json==" + response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CommonUtil.showToast(mActivity, "网络连接失败");
            }
        });
    }
}
